package com.blrs.controller;

import java.util.List;
import java.util.Objects;
import javax.servlet.http.HttpServletResponse;

import com.blrs.common.utils.SecurityUtils;
import com.blrs.common.utils.uuid.UUID;
import com.blrs.service.enterprise.seas.IHighSeaRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;
import com.blrs.domain.HighSeaRecord;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 公海记录进展Controller
 * 
 * @author yang
 * @date 2023-09-28
 */
@RestController
@RequestMapping("/sea/record")
public class HighSeaRecordController extends BaseController
{
    @Autowired
    private IHighSeaRecordService highSeaRecordService;

    /**
     * 查询公海记录进展列表
     */
    //@PreAuthorize("@ss.hasPermi('sea:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(HighSeaRecord highSeaRecord)
    {
        startPage();
        List<HighSeaRecord> list = highSeaRecordService.selectHighSeaRecordList(highSeaRecord);
        return getDataTable(list);
    }

    /**
     * 导出公海记录进展列表
     */
    //@PreAuthorize("@ss.hasPermi('sea:record:export')")
    @Log(title = "公海记录进展", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HighSeaRecord highSeaRecord)
    {
        List<HighSeaRecord> list = highSeaRecordService.selectHighSeaRecordList(highSeaRecord);
        ExcelUtil<HighSeaRecord> util = new ExcelUtil<HighSeaRecord>(HighSeaRecord.class);
        util.exportExcel(response, list, "公海记录进展数据");
    }

    /**
     * 获取公海记录进展详细信息
     */
    //@PreAuthorize("@ss.hasPermi('sea:record:query')")
    @GetMapping(value = "/{recordsId}")
    public AjaxResult getInfo(@PathVariable("recordsId") String recordsId)
    {
        return success(highSeaRecordService.selectHighSeaRecordByRecordsId(recordsId));
    }

    /**
     * 新增公海记录进展
     */
    //@PreAuthorize("@ss.hasPermi('sea:record:add')")
    @Log(title = "公海记录进展", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HighSeaRecord highSeaRecord)
    {
        highSeaRecord.setRecordsId(UUID.randomUUID().toString().replaceAll("-", ""));
        highSeaRecord.setFollowId(SecurityUtils.getUserId());
        return toAjax(highSeaRecordService.insertHighSeaRecord(highSeaRecord));
    }

    /**
     * 修改公海记录进展
     */
    //@PreAuthorize("@ss.hasPermi('sea:record:edit')")
    @Log(title = "公海记录进展", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HighSeaRecord highSeaRecord)
    {
        return toAjax(highSeaRecordService.updateHighSeaRecord(highSeaRecord));
    }

    /**
     * 删除公海记录进展
     */
    //@PreAuthorize("@ss.hasPermi('sea:record:remove')")
    @Log(title = "公海记录进展", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordsIds}")
    public AjaxResult remove(@PathVariable String[] recordsIds)
    {
        return toAjax(highSeaRecordService.deleteHighSeaRecordByRecordsIds(recordsIds));
    }
}
